using System.Net;
using BrettM.Restful.SDK;
using BrettM.Web.Http;

namespace BrettM.Web.Restful
{

    public class HttpCreatedResult : HttpResult
    {
        public string Url { get; set; }
        public string ETag { get; set; }

        public HttpCreatedResult(string url)
            : base(HttpStatusCode.Created)
        {
            Url = url;
        }

        public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
        {
            base.ExecuteResult(context);

            context.HttpContext.Response.AddHeader("Location", Url);
            if( !string.IsNullOrEmpty(ETag))
                context.HttpContext.Response.AddHeader("ETag", ETag);
        }
    }
}
